import java.sql.*;
public class Main {
    public static void main(String[] args) {
    }
private static void m1() {
            String URL = "jdbc:mysql://127.0.0.1:3306/mybatis?characterEncoding=utf-8";
            String USER = "root";
            String PASSWORD = "root";
            Connection conn = null;
            PreparedStatement preparedStatement=null;
            ResultSet resultSet=null;
            try {
                //1.加载驱动
                Class.forName("com.mysql.jdbc.Driver");
                //2.获取连接
                conn = DriverManager.getConnection(URL, USER, PASSWORD);

                //3.sql语句
                String sql = "sql * from sys_user";

                //4.预处理
                PreparedStatement prepareStatement = conn.prepareStatement(sql);

                //6.执行sql语句

                resultSet = preparedStatement.executeQuery();
                //7.判断是否成功
                while (resultSet.next()) {
                    int id = resultSet.getInt(1);
                    String name = resultSet.getString(2);
                    String password = resultSet.getString(3);
                    System.out.println(id+""+name+""+password);
                }
                //8.返回视图

            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }finally {
                try{
                    if(resultSet !=null){
                        resultSet.close();
                    }
                    if(preparedStatement !=null){
                        preparedStatement.close();
                    }
                    if(conn!=null){
                        conn.close();
                }

                }catch (SQLException e){
                    throw new RuntimeException(e);
                }
            }
    }


    private static void m2() {
    }
}

